package com.java.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.dao.ApplyMapper;
import com.java.dto.ApplyDTO;
import com.java.model.AdvertisersAccount;
import com.java.model.Apply;
import com.java.model.Booking;
import com.java.model.Result;
import com.java.service.ApplyService;
import com.java.service.BookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ApplyServiceImpl implements ApplyService {

    @Autowired
    private ApplyMapper applyMapper;

    @Autowired
    private BookingService bookingService;

    @Override
    public Result save(Apply apply) {
        applyMapper.save(apply);
        return Result.success();
    }

    @Override
    public Result modify(Apply apply) {
        return null;
    }

    @Override
    public Result remove(int[] ids) {
        return null;
    }

    /**
     * 自媒体
     * @param apply
     * @return
     */
    @Override
    public Result list(Apply apply) {
        PageHelper.startPage(apply.getPageNum(), apply.getPageSize()); // 提醒page在显示哪一页的数据和要显示多少条数据
        List<Apply> list = applyMapper.list(apply);
        PageInfo<Apply> pageInfo = new PageInfo<>(list);

        return Result.success(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 管理员
     * @param apply
     * @return
     */
    @Override
    public Result adminList(Apply apply) {
        PageHelper.startPage(apply.getPageNum(), apply.getPageSize()); // 提醒page在显示哪一页的数据和要显示多少条数据
        List<Apply> list = applyMapper.adminList(apply);
        PageInfo<Apply> pageInfo = new PageInfo<>(list);

        return Result.success(pageInfo.getList(), pageInfo.getTotal());
    }

    @Override
    public Result get(int id) {
        return null;
    }

    @Override
    public Result save(ApplyDTO applyDTO) {
        applyMapper.save(applyDTO);
        return Result.success();
    }

    @Override
    public List<Apply> toList() {
        return applyMapper.toList();
    }

    /**
     * 自媒体投放申请同意
     * @param apply
     * @return
     */
    @Override
    public Result modifyAudit(Apply apply) {
        apply.setStatus(2);
        applyMapper.modifyAudit(apply);
        return Result.success();
    }

    /**
     * 管理员投放申请同意
     * @param apply
     * @return
     */
    @Override
    public Result adminAgree(Apply apply) {
        apply.setStatus(3);
        applyMapper.modifyAudit(apply);
        return Result.success();
    }

    /**
     * 拒绝审核操作
     * @param apply
     * @return
     */
    @Override
    public Result refused(Apply apply) {
        apply.setStatus(4);
        applyMapper.refused(apply);
        return Result.success();
    }

}
